<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <chind1></chind1>
        <chind2></chind2>
        <button @click="logData">打印两个子组件的值</button>
    </div>
    <script src="../js/vue.js"></script>
    <template id="chind1">
        <div>{{ name }}</div>
    </template>
    <template id="chind2">
        <div>{{ name }}</div>
    </template>
    <script>
        const app = new Vue({
            el:'#app',
            data(){
                return {
                }
            },
            components:{
                'chind1':{
                    template:'#chind1',
                    data(){
                        return {
                            name:'我是组件1'
                        }
                    }
                },
                'chind2':{
                    template:'#chind2',
                    data(){
                        return {
                            name:'我是组件2'
                        }
                    },
                    methods:{
                        changeName(){
                            this.name = '修改以后的name'
                        }
                    }
                }
            },
            methods:{
                logData(){
                    console.log(this.$children[0].name)
                    console.log(this.$children[1].name)
                    this.$children[1].changeName()
                }
            }
        })
    </script>
</body>
</html>